package com.zxjia.ssmp.controller;

import com.zxjia.ssmp.api.UserApiService;
import com.zxjia.ssmp.dto.MemberAddressRequest;
import com.zxjia.ssmp.vo.MemberAddressVo;
import com.zxjia.ssmp.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value = "/api")
public class UserController {

    @Autowired
    UserApiService userApiService;

    /**
     * 跳转到收获地址页面
     */
    @GetMapping(value = "/user/toReceivingAdress")
    public String toReceivingAdress(MemberAddressRequest request, HttpServletRequest httpServletRequest) {
        httpServletRequest.setAttribute("request",request);
        httpServletRequest.setAttribute("address", userApiService.getMemberAddress(request));
        return "receiving-adress-list.html";
    }

    /**
     * 跳转到添加地址页面
     */
    @GetMapping(value = "/user/toAddAdress")
    public String toAddAdress(MemberAddressRequest request, HttpServletRequest httpServletRequest) {
        httpServletRequest.setAttribute("request",request);
        return "receiving-adress.html";
    }

    @GetMapping(value = "/user/getMemberAddress")
    public ResultVO<List<MemberAddressVo>> getMemberAddress(MemberAddressRequest request) {
        return ResultVO.success(userApiService.getMemberAddress(request));
    }
}
